import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/wroks/search_bean.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/http/bean/ywx_limit.dart';
import 'package:app/src/ui/popuwindow/popuwindow_search.dart';
import 'package:app/src/ui/route/works/public/review_list.dart';

///外车运费审核
class CarFreightRatesRoute extends StatefulWidget {
  YwxItem item;

  CarFreightRatesRoute(this.item);

  @override
  _State createState() => _State();
}

class _State extends State<CarFreightRatesRoute> {
  _Presenter presenter = _Presenter();

  @override
  void initState() {
    super.initState();
    if (presenter.searchInfo == null) {
      presenter.searchInfo = SearchInfo(widget.item)
        // ..isShowContractCode = true //合同编号
        // ..isShowOutCode = true //合同外部编号
        // ..isShowProjectName = true //项目名称
        // ..isShowCustomerName = true //客户名称
        // ..isShowMerchandiserName = true //客服经理
        // ..isShowSalesmanName = true //销售经理
        // ..isShowProcessName = true //所属工序
        // ..isShowApplicationClassName = true; //申请班组
        ..isShowTheName = true; //姓名
    }
  }

  @override
  Widget build(BuildContext context) {
    px.init(context);
    presenter?.searchInfo?.showAddTime =
        AppStrings.of(context).AddDate9; //fixme 搜索条件，申请日期改成：上报日期。
    var scaffold = AppUi.getScaffoldWithReView(
        context, _body(context), widget.item, presenter.searchInfo!, () {
      //print("===============================================================搜索刷新");
      presenter.setStateBody?.call(() {});
    });
    return WillPopScope(
      child: scaffold,
      onWillPop: () async {
        return true; //true 不屏蔽返回键
      },
    );
  }

  Widget _body(BuildContext context) {
    //print("===============================================================页面刷新:$isShowPopuMenuWithSearch");
    return StatefulBuilder(
        builder: (BuildContext context, StateSetter setState) {
      presenter.setStateBody = setState;
      List<Widget> children = [];
      //搜索条件
      var searchLayout =
          AppUi.getSearchLayout(context, presenter.searchInfo!, () {
        presenter.setStateBody?.call(() {});
      });
      children.add(searchLayout);
      //审核列表
      var reviewList = ReviewList(widget.item, presenter.searchInfo!, true);
      children.add(Expanded(child: reviewList));
      return Column(
        children: children,
      );
    });
  }
}

class _Presenter {
  ///搜索条件
  SearchInfo? searchInfo = null;

  ///body视图状态
  StateSetter? setStateBody;
}
